<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户管理</title>
    <link rel="stylesheet" href="../../../assert/css/font.css" th:href="@{/assert/css/font.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrap.min.css" th:href="@{/assert/css/bootstrap.min.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrap-table.css" th:href="@{/assert/css/bootstrap-table.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrap-select.min.css"
          th:href="@{/assert/css/bootstrap-select.min.css}"/>
    <link rel="stylesheet" href="../../../assert/css/bootstrapValidator.css"
          th:href="@{/assert/css/bootstrapValidator.css}"/>
    <link rel="stylesheet" href="../../../assert/css/toastr.min.css" th:href="@{/assert/css/toastr.min.css}"/>
    <link href="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css" rel="stylesheet"
          th:href="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css}"/>
    <link rel="stylesheet" href="../../../assert/css/style.css" th:href="@{/assert/css/style.css}"/>
    <link rel="stylesheet" href="../../../assert/css/index.css"
          th:href="@{/assert/css/index.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"/>
    <link rel="stylesheet" href="../../../assert/css/common.css" th:href="@{/assert/css/common.css}"/>
    <link href="../../../assert/css/plugin/jsTree/themes/default/style.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/jsTree/themes/default/style.css}">
    <link rel="stylesheet" href="../../../assert/js/bootstrap-fileinput/css/fileinput.min.css"
          th:href="@{/assert/js/bootstrap-fileinput/css/fileinput.min.css}"/>
    <style>
        .search_group label {
            width: 110px;
        }

        .importTips {
            padding-left: 100px;
        }

        .importTips li {
            line-height: 26px;
        }

        .importTips li span {
            display: inline-block;
            width: 20px;
            position: relative;
            left: 10px;
            top: -3px;
        }

        /*用户授权弹窗右侧不可编辑节点背景色*/
        #jstreeR.jstree-default .jstree-disabled {
            color:rgba(0,0,0,.5);
        }

        /*.table {table-layout:fixed;}*/
    </style>
</head>
<body class="laydate_body">
<div class="wrapper wrapper-content">
    <div class="ibox">
        <!--<div class="con-title">-->
        <!--<h4>用户管理</h4>-->
        <!--</div>-->
        <div class="resourceCon">
            <div class="con-operation clearfix">
                <div class="cquery  clearfix">
                    <div class="search_group">
                        <label class="control-label">省份:</label>
                        <div class="control-inline">
                            <select class="mechanTypepicker selectpicker" id="areaIdSearch"></select>
                        </div>
                    </div>
                    <div class="search_group">
                        <label class="control-label">所属组织机构:</label>
                        <div class="control-inline">
                            <div class="input-group" data-toggle="modal" data-target="#orgModal">
                                <input type="hidden" class="form-control" id="groupIdSearch"
                                       aria-describedby="basic-addon1">
                                <input type="text" class="form-control" placeholder="请选择所属组织机构"
                                       id="groupNameSearch" aria-describedby="basic-addon1">
                                <span class="input-group-addon" id="basic-addon1"><i
                                        class="glyphicon glyphicon-search"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="search_group">
                        <label class="control-label">工号:</label>
                        <div class="control-inline">
                            <input type="text" class="form-control" id="accountSearch" placeholder="请输入工号">
                        </div>
                    </div>
                    <div class="search_group">
                        <label class="control-label">用户名/登录名:</label>
                        <div class="control-inline">
                            <input type="text" class="form-control" id="userNameSearch"
                                   placeholder="请输入用户名（登录名）">
                        </div>
                    </div>
                    <div class="search_group">
                        <label class="control-label">真实姓名:</label>
                        <div class="control-inline">
                            <input type="text" class="form-control" id="realNameSearch" placeholder="请输入真实姓名">
                        </div>
                    </div>
                    <div class="search_group">
                        <label class="control-label">状态:</label>
                        <div class="control-inline">
                            <select id="isDeleteSearch" class="selectpicker userStatus" data-live-search="true"
                                    data-live-search-style="begins" title="请选择状态" multiple>
                            </select>
                        </div>
                    </div>
                    <div class="search_group">
                        <button id="searchBtn" type="button" class=" querybtn btn btn-danger">查询</button>
                        <button id="reset" type="reset" class="btn  btn-default">重置</button>

                    </div>
                </div>
                <div class="obtns clearfix">
                    <button class="btn btn-default" type="button" data-toggle="modal" data-target="#userModal">
                        <i class="fa fa-plus"></i>添加用户
                    </button>
                    <button id="editBtn" class="btn btn-default" type="button">
                        <i class="fa fa-pencil"></i>修改
                    </button>
                    <button id="batchDeleteBtn" class="btn btn-default" type="button" data-toggle="modal"><i
                            class="fa fa-trash"></i>删除
                    </button>
                    <button id="batchOnBtn" class="btn btn-default" type="button"><i
                            class="fa fa-power-off"></i>启用
                    </button>
                    <button id="batchOffBtn" class="btn btn-default" type="button"><i
                            class="fa fa-stop"></i>停用
                    </button>
                    <button id="passwordInitBtn" class="btn btn-default" type="button"><i
                            class="glyphicon glyphicon-off"></i>重置密码
                    </button>
                    <button id="powerBtn" class="btn btn-default" type="button"><i
                            class="fa fa-get-pocket"></i>授权
                    </button>
                    <button id="importUser" class="btn btn-default" type="button" data-toggle="modal"
                            data-target="#importModal"><i
                            class="fa fa-upload"></i>导入
                    </button>
                    <button id="exportExcelBtn1" class="btn btn-default" type="button"><i
                            class="glyphicon glyphicon-upload"></i>导出
                    </button>
                    <button id="exportExcelBtn2" class="btn btn-default hidden" type="button"><i
                            class="glyphicon glyphicon-upload"></i>导出用户详细信息
                    </button>
                    <form id="exportForm" hidden method="post">
                        <input type="hidden" name="code"/>
                        <input type="hidden" name="areaId"/>
                        <input type="hidden" name="groupId"/>
                        <input type="hidden" name="seatGroup"/>
                        <input type="hidden" name="userName"/>
                        <input type="hidden" name="realName"/>
                        <input type="hidden" name="account"/>
                        <input type="hidden" name="status"/>
                        <input type="hidden" name="fileContent"/>
                        <input type="hidden" name="fileContext"/>
                        <input type="hidden" name="sortName"/>
                        <input type="hidden" name="sortOrder"/>
                        <input type="hidden" name="userIdList"/>
                    </form>
                </div>
            </div>
        </div>

        <table id="userTable"></table>
        <!-- 用户管理Modal -->
        <div class="modal fade" id="userModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">添加用户</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="userManageForm">
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>所属组织机构:</label>
                                <div class="col-sm-9">
                                    <input type="hidden" class="form-control" name="groupid"/>
                                    <input type="text" class="form-control" name="groupname" placeholder="请选择所属组织机构"
                                           readonly style="background: #fff"/>
                                    <div id="addTree" class="otree"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>工号:</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="account" placeholder="请输入工号"
                                           style="padding-right:12px;">
                                </div>
                                <label class="col-sm-2 control-label">登录名:</label>
                                <div class="col-sm-4">
                                    <input type="hidden" name="areaId"/>
                                    <input type="hidden" name="provinceCode"/>
                                    <input type="hidden" name="username"/>
                                    <span id="usernameAddSpan"
                                          style="margin-top:1px; display:inline-block;line-height:30px;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>姓名:</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="realname" placeholder="请输入姓名"
                                           style="padding-right:12px;">
                                </div>
                                <label class="col-sm-2 control-label"><span class="respan">*</span>手机号:</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="mobileno" placeholder="请输入手机号码"
                                           style="width: 136px;padding-right:12px;">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>身份证号：</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="idcard" placeholder="请输入身份证号">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>邮箱：</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="email" placeholder="请输入邮箱地址">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">备注:</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" name="note" placeholder="请输入内容"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">启用否:</label>
                                <div class="col-sm-9">
                                    <select class="resourceTypepicker selectpicker userStatus" name="isdelete"
                                            id="isDeleteAdd">
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">选择角色:</label>
                                <div class="col-sm-9">
                                    <div class="rrow clearfix" id="roleListAddDiv">
                                    </div>
                                </div>
                            </div>
                            <button type="reset" id="addResetBtn" hidden>重置</button>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="savebtn btn btn-primary" id="addSaveBtn">保存</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--用户修改modal -->
        <div class="modal fade" id="editUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">修改用户</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="editUserForm">
                            <input type="hidden" id="userId" name="id" value=""/>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>所属组织机构：</label>
                                <div class="col-sm-9">
                                    <input type="hidden" class="form-control" name="groupid"/>
                                    <input type="text" class="form-control" name="groupname" placeholder="请选择所属组织机构"
                                           readonly style="background: #fff"/>
                                    <div id="editTree" class="otree"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>工号：</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="account" placeholder="请输入工号"
                                           style="padding-right:12px;">

                                </div>
                                <label class="col-sm-2 control-label">登录名：</label>
                                <div class="col-sm-4">
                                    <input type="hidden" name="provinceCode"/>
                                    <input type="hidden" name="username">
                                    <span id="usernameEditSpan"
                                          style="margin-top:1px; display:inline-block;line-height:30px;"></span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>姓名：</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" name="realname" placeholder="请输入姓名"
                                           style="padding-right:12px;">
                                </div>
                                <label class="col-sm-2 control-label"><span class="respan">*</span>手机号：</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="mobileno" placeholder="请输入手机号码"
                                           style="width: 136px;padding-right:12px;">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>身份证号：</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="idcard" placeholder="请输入身份证号">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="respan">*</span>邮箱：</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" name="email" placeholder="请输入邮箱地址">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">备注：</label>
                                <div class="col-sm-9">
                                    <textarea class="form-control" name="note" placeholder="请输入内容"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">选择角色：</label>
                                <div class="col-sm-9">
                                    <div class="rrow" id="roleListEditDiv">
                                    </div>
                                </div>
                            </div>
                            <button type="reset" id="editResetBtn" hidden>重置</button>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="savebtn btn btn-primary" id="editSaveBtn">保存</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!--删除确定 modal -->
        <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <input type="hidden" id="deleteId" value=""/>
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="deleteModalLabel">删除用户</h4>
                    </div>
                    <div class="modal-body">
                        <p>确定删除吗</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--删除用户二次确认-->
        <div class="modal fade" id="delete2Modal" tabindex="-1" role="dialog" aria-labelledby="delete2ModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="delete2ModalLabel">删除用户</h4>
                    </div>
                    <div class="modal-body">
                        <p>是否继续操作？</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--确认modal -->
        <div class="modal fade" id="enshureModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">导入用户</h4>
                    </div>
                    <div class="modal-body" id="enshureModal-text">
                        <p>导入成功</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <!--用户启用停用 确认madal 第一次-->
        <div class="modal fade" id="firstModal" tabindex="-1" role="dialog" aria-labelledby="firstModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <input type="hidden" id="ids" value=""/>
                <input type="hidden" id="status" value=""/>
                <input type="hidden" id="successTips"/>
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="firstModalLabel">标题行</h4>
                    </div>
                    <div class="modal-body">
                        <p id="firstTips">提示内容</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--用户启用停用 确认madal 第二次-->
        <div class="modal fade" id="secondModal" tabindex="-1" role="dialog" aria-labelledby="secondModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="secondModalLabel">标题行</h4>
                    </div>
                    <div class="modal-body">
                        <p id="secondTips">提示内容</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!--用户密码重置 确认madal 第一次-->
        <div class="modal fade" id="passResetModal" tabindex="-1" role="dialog" aria-labelledby="passResetModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <input type="hidden" id="resetId" value=""/>
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="passResetModalLabel">重置密码</h4>
                    </div>
                    <div class="modal-body">
                        <p>是否重置成初始密码</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <!--用户密码重置 确认madal 第二次-->
        <div class="modal fade" id="passReset2Modal" tabindex="-1" role="dialog" aria-labelledby="passReset2ModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="passReset2ModalLabel">重置密码</h4>
                    </div>
                    <div class="modal-body">
                        <p>是否继续操作</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!--所属机构弹窗-->
        <div class="modal fade" id="orgModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel32"
             data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">
                            机构选择
                        </h4>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" id="chooseId"/>
                        <input type="hidden" id="chooseName"/>
                        <div id="groupChooseTree"></div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!--导入 modal -->
        <div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             data-backdrop=false>
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">
                            导入
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal" role="form" id="importForm">
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>请选择省份：</label>
                                <div class="col-sm-7">
                                    <select class="resourceTypepicker selectpicker" name="areaid">
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"><span class="respan">*</span>上传：</label>
                                <div class="col-sm-7" id="uploadDiv">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label"></label>
                                <div class="col-sm-7">
                                    <button type="button" class="btn btn-outline btn-default"
                                            onclick="window.location.href=basePath+'app/template/人员信息导入表模板.xls';">
                                        点击获取模板文件
                                    </button>
                                </div>
                            </div>
                        </form>
                        <div>
                            <ul class="importTips">
                                <li><span>●</span>导入的 “类型” 必须是运营管理、质检或坐席。</li>
                                <li><span>●</span>导入的 “角色” 必须在模板内角色sheet表中存在，</li>
                                <li><span></span>另外要与角色管理中的角色信息对应。</li>
                                <li><span>●</span>用户的手机号、身份证号、邮箱不能重复。</li>
                            </ul>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="csavebtn btn btn-primary" id="importConfirmBtn">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>

        <!--授权modal-->
        <div class="modal fade" id="powerModal" tabindex="-1" role="dialog" aria-labelledby="myModalP"
             data-backdrop=false>
            <div class="modal-dialog" role="document" style="width:600px;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalP">授权</h4>
                    </div>
                    <div class="modal-body" style="overflow: hidden;padding:15px 20px 20px 20px;">
                        <div class="powerLeft">
                            <h4>未授权</h4>
                            <div class="boxP">
                                <div class="search_box">
                                    <input type="text" style="width: 172px;padding:1px 5px;"
                                           autocomplete="off"><span class="fa fa-search fa_btn"
                                                                    style="width: 24px;height: 24px;"></span>
                                </div>
                                <div id="jstreeL" class="scrollbar">

                                </div>
                            </div>
                        </div>
                        <div class="powerMiddle">
                            <button class="fa fa-hand-o-right" title="授权" id="authon"></button>
                            <button class="fa fa-hand-o-left" title="撤销" id="unAuthon"></button>
                        </div>
                        <div class="powerRight">
                            <h4>已授权</h4>
                            <div class="boxP">
                                <div class="search_box">
                                    <input type="text" style="width: 172px;padding:1px 5px;"
                                           autocomplete="off"><span class="fa fa-search fa_btn"
                                                                    style="width: 24px;height: 24px;"></span>
                                </div>
                                <div id="jstreeR" class="scrollbar">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--导出确认框-->
        <div class="modal fade" id="exportModal" tabindex="-1" role="dialog" aria-labelledby="exportP"
             data-backdrop=false>
            <div class="modal-dialog" role="document" style="width:600px;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="exportP">导出申请</h4>
                    </div>
                    <div class="modal-body" style="overflow: hidden;padding:15px 20px 20px 20px;">
                        <div>请选择导出内容 <p class="exportAll on">全部 <span class="fa fa-check-square-o"></span></p></div>
                        <ul class="tableColums">
                            <li class="on" data-code="area">省份 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="groupname">部门（班组） <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="grouptype">类型 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="rolename">角色 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="username">登录名 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="realname">姓名 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="account">工号 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="mobileno">手机号 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="idcard">身份证号 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="email">邮箱 <span class="fa fa-check-square-o"></span></li>
                            <li class="on" data-code="workip">办公网出口ip <span class="fa fa-check-square-o"></span></li>
                        </ul>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="exportSaveBtn btn btn-primary">确定</button>
                        <button type="button" class="cancelbtn btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<a id="basePath" th:href="@{/}"></a>
<script src="../../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/bootstrap.min.js" th:src="@{/assert/js/bootstrap.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<!--<script src="../../../assert/js/bootstrap-table.js" th:src="@{/assert/js/bootstrap-table.js}"></script>-->
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/bootstrap-select.js" th:src="@{/assert/js/bootstrap-select.js}"></script>
<script src="../../../assert/js/bootstrapValidator.js" th:src="@{/assert/js/bootstrapValidator.js}"></script>
<script src="../../../assert/js/base.js"
        th:src="@{/assert/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/toastr.min.js" th:src="@{/assert/js/toastr.min.js}"></script>
<script src="../../../assert/js/plugin/jsTree/jstree.min.js"
        th:src="@{/assert/js/plugin/jsTree/jstree.min.js}"></script>
<script src="../../../assert/js/bootstrap-fileinput/js/fileinput.min.js"
        th:src="@{/assert/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script src="../../../assert/js/bootstrap-fileinput/js/locales/zh.js"
        th:src="@{/assert/js/bootstrap-fileinput/js/locales/zh.js}"></script>
<script src="../../../assert/js/common.js"
        th:src="@{/assert/js/common.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script type="text/javascript">
    //项目名称
    var basePath = $("#basePath").attr("href");
    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#userTable').bootstrapTable({
                url: basePath + "rest/users/usersByPage", //请求后台的URL（*）
                method: "post", //请求方式（*）
                dataType: "json",
                contentType: "application/x-www-form-urlencoded;charset=UTF-8",
                dataField: "rows", //服务端返回数据键值 就是说记录放的键值是rows，分页时使用总记录数的键值为total
                totalField: "total",
                striped: true, //是否显示行间隔色
                cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true, //是否显示分页（*）
                sortable: true, //是否启用排序
                sortName: "id", //排序方式
                sortOrder: "desc", //排序方式
                clickToSelect: true,
                queryParams: oTableInit.queryParams, //传递参数（*）
                queryParamsType: "", //  queryParamsType = 'limit' 参数: limit, offset, search, sort, order;
                sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1, //初始化加载第一页，默认第一页
                pageSize: 10, //每页的记录行数（*）
                pageList: [10, 15, 20, 25], //可供选择的每页的行数（*）
                idField: "id",
                uniqueId: "id", //每一行的唯一标识，一般为主键列
                columns: [{
                    field: 'id',
                    title: 'ID',
                    sortable: true,
                    visible: false
                }, {
                    field: 'checkStatus',
                    title: '全选',
                    checkbox: true
                }, {
                    field: 'area',
                    title: '省份',
                    sortable: false,
                    formatter: function (value, row, index) {
                        var group = row.group;
                        if (group.areaname != null) {
                            return group.areaname;
                        } else {
                            return "集团";
                        }
                    }
                }, {
                    field: 'group',
                    title: '所属组织机构',
                    sortable: false,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.name;
                        }
                    }
                }, {
                    field: 'rolelist',
                    title: '角色',
                    sortable: false,
                    formatter: function (value, row, index) {
                        if (value.length > 0) {
                            var roleName = [];
                            $.each(value, function (index, role) {
                                roleName.push(role.name);
                            });
                            return roleName.join(",");
                        }
                    }
                }, {
                    field: 'username',
                    title: '登录名',
                    sortable: true
                }, {
                    field: 'realname',
                    title: '真实姓名',
                    sortable: true
                }, {
                    field: 'account',
                    title: '工号',
                    sortable: true
                }, {
                    field: 'mobileno',
                    title: '手机号',
                    sortable: true
                }, {
                    field: 'idcard',
                    title: '身份证号',
                    sortable: true
                }, {
                    field: 'email',
                    title: '邮箱',
                    sortable: true
                }, {
                    field: 'createtime',
                    title: '创建时间',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            // 把时间戳修改为yyyy-mm-dd HH:mm:ss格式
                            var date = new Date(value);
                            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                            var hour = date.getHours();
                            var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                            var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                            return date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second;
                        }
                    }
                }, {
                    field: 'lastlogintime',
                    title: '最后登录时间',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            // 把时间戳修改为yyyy-mm-dd HH:mm:ss格式
                            var date = new Date(value);
                            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                            var hour = date.getHours();
                            var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                            var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                            return date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second;
                        }
                    }
                }, {
                    field: 'note',
                    title: '备注',
                    width: 200,
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (value == null) {
                            value = ""
                        }
                        return "<div class='onoteBoxTable' title='" + value + "'>" + value + "</div>";
                    }
                }, {
                    field: 'isdelete',
                    title: '状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return row.statusname;
                    }
                }],
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () { //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadSuccess: function (data) {  //加载成功时执行
                    resize.me();
                },
                onLoadError: function (data) {
                    $('#userTable').bootstrapTable('removeAll');
                },
                responseHandler: function (res) {
                    return {
                        total: res.totalCount,
                        rows: res.result
                    };
                }
            });
        };
        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var areaId = $("#areaIdSearch").selectpicker("val");
            var temp;
            if (areaId == undefined) {
                temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    "pageSize": params.pageSize,
                    "pageNum": params.pageNumber,
                    "sortName": this.sortName,
                    "sortOrder": this.sortOrder,
                    "groupId": $("#groupIdSearch").val(),
                    "userName": $.trim($("#userNameSearch").val()),
                    "realName": $.trim($("#realNameSearch").val()),
                    "account": $.trim($("#accountSearch").val()),
                    "isDelete": $("#isDeleteSearch").val() != null ? $("#isDeleteSearch").val().join(",") : null
                };
            } else {
                temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    "pageSize": params.pageSize,
                    "pageNum": params.pageNumber,
                    "sortName": this.sortName,
                    "sortOrder": this.sortOrder,
                    "areaId": areaId,
                    "groupId": $("#groupIdSearch").val(),
                    "userName": $.trim($("#userNameSearch").val()),
                    "realName": $.trim($("#realNameSearch").val()),
                    "account": $.trim($("#accountSearch").val()),
                    "isDelete": $("#isDeleteSearch").val() != null ? $("#isDeleteSearch").val().join(",") : null
                };
            }
            // 导出的时候 保证excel里面的排序和页面展示一致
            $("#exportForm input[name='sortName']").val(this.sortName);
            $("#exportForm input[name='sortOrder']").val(this.sortOrder);
            return temp;
        };
        return oTableInit;
    };

    // 添加用户
    var userAddFun = {
        init: function () {
            userAddFun.formInit();
            userAddFun.showAddTree();
            userAddFun.save();
        },
        formInit: function () {
            // 初始化表单
            $("#userModal").on("show.bs.modal", function () {
                // 文本框初始化
                $("#addResetBtn").click();
                // 隐藏域不能自动清空 手动清空
                $("#userManageForm input[name='groupid']").val("");
                $("#userManageForm input[name='provinceCode']").val("");
                $("#usernameAddSpan").text("");
                // 加载角色信息
                $.get(basePath + "rest/role/getAllRoleByUser", function (data) {
                    if (data != null) {
                        $("#roleListAddDiv").html("");
                        $.each(data, function (index, role) {
                            $("#roleListAddDiv").append("<div class='ritem'><input type='checkbox' name='roleidlist' value='" + role.id + "'/><span>" + role.name + "</span></div>");
                        })
                    }
                });
                // 树初始化
                userAddFun.addTreeInit();
            });
            // 工号输入框失去焦点后 触发的事件
            $("#userManageForm input[name='account']").off("keyup").on("keyup", function () {
                var provinceCode = $("#userManageForm input[name='provinceCode']").val();
                var account = $(this).val();
                if (account != '') {
                    $("#userManageForm input[name='username']").val(provinceCode + account);
                    $("#usernameAddSpan").text(provinceCode + account);
                }
            });
            // 初始化省份code
            $("#userManageForm input[name='provinceCode']").val("");
        },
        addTreeInit: function () {
            $('#addTree').jstree("destroy");
            $('#addTree').data('jstree', false).empty();
            $("#addTree").jstree({
                "core": {
                    "animation": false,
                    "multiple": false,
                    "check_callback": true,
                    'data': function (obj, callback) {
                        $.ajax({
                            type: "GET",
                            url: basePath + 'rest/group/showGroupTree',
                            dataType: "json",
                            async: false,
                            success: function (result) {
                                if (result != null) {
//                                    var arr = [];
//                                    arr.push(result);
                                    callback.call(this, orgTree.loopMenu(result, true));
                                }
                            }
                        });
                    }
                },
                "types": {
                    "default": {
                        "icon": "jstree-folder"
                    },
                    "html": {
                        "icon": "jstree-file"
                    }
                },
                "plugins": ["types", "search", "unique"]
            });
            // 修改选中的节点事件
            $('#addTree').on("changed.jstree", function (e, data) {
                if (data.selected > 0) {
                    var groupId = data.selected;
                    $("#userManageForm input[name='groupid']").val(groupId);
                    $("#userManageForm input[name='groupname']").val(data.instance.get_selected(true)[0].text);
                    $("#addTree").css("display", "none");
                    // 获取机构id对应的省份编码 用来给用户名赋值
                    $.get(basePath + "rest/group/selectProvinceCodeByGroupId?groupId=" + groupId, function (data) {
                        $("#userManageForm input[name='provinceCode']").val(data);
                        // 读取判断工号是否输入了值
                        var account = $("#userManageForm input[name='account']").val();
                        if (account != '') {
                            $("#userManageForm input[name='username']").val(data + account);
                            $("#usernameAddSpan").text(data + account);
                        }
                    });
                }
            });
        },
        showAddTree: function () {
            $("#userManageForm input[name='groupname']").off("click").on("click", function () {
                // 显示树 需要做成自动显示和隐藏
                $("#addTree").css("display", "block");
            });
        },
        save: function () {
            $("#addSaveBtn").off("click").on("click", function () {
                var bv = $('#userManageForm').data('bootstrapValidator');
                bv.validate();
                if (bv.isValid()) {
                    $.ajax({
                        type: "post",
                        url: basePath + "rest/users/userAdd",
                        data: $("#userModal form").serialize(),
                        success: function (data) {
                            if (data.type == "success") {
                                $("#userModal").modal("hide");
                                $("#userTable").bootstrapTable("refresh");
                                toastr.success("用户添加成功");
                            } else {
                                toastr.error(data.message);
                            }
                        }
                    });
                }
            });
        }
    };

    // 修改用户
    var userEditFun = {
        init: function () {
            userEditFun.openEditModal();
            userEditFun.formInit();
            userEditFun.showEditTree();
            userEditFun.save();
        },
        openEditModal: function () {
            $("#editBtn").off("click").on("click", function () {
                var rows = $("#userTable").bootstrapTable("getSelections");
                if (rows.length == 0) {
                    toastr.error('请选择行');
                } else if (rows.length > 1) {
                    toastr.error('单次只能选择一行进行修改');
                } else {
                    var userId = rows[0].id;
                    $("#userId").val(userId);
                    $("#editUserModal").modal("show");
                }
            });
        },
        formInit: function () {
            // 初始化表单
            $("#editUserModal").on("show.bs.modal", function () {
                var userId = $("#userId").val();
                $.ajax({
                    type: "post",
                    url: basePath + "rest/users/getUserByPK",
                    data: {id: userId},
                    success: function (data) {
                        if (data != "") {
                            if (data.group != null) {
                                $("#editUserModal input[name='groupid']").val(data.groupid).attr("oldvalue", data.groupid);
                                $("#editUserModal input[name='groupname']").val(data.group.name);
                            } else {
                                $("#editUserModal input[name='groupid']").val("").attr("oldvalue", "");
                                $("#editUserModal input[name='groupname']").val("");
                            }
                            $("#editUserModal input[name='username']").val(data.username).attr("oldvalue", data.username);
                            $("#usernameEditSpan").text(data.username);
                            $("#editUserModal input[name='realname']").val(data.realname);
                            $("#editUserModal input[name='account']").val(data.account).attr("oldvalue", data.account);
                            $("#editUserModal input[name='mobileno']").val(data.mobileno);
                            $("#editUserModal input[name='email']").val(data.email).attr("oldvalue", data.email);
                            $("#editUserModal input[name='idcard']").val(data.idcard).attr("oldvalue", data.idcard);
                            $("#editUserModal :input[name='note']").val(data.note);
                            $("#editUserModal :input[name='isdelete']").selectpicker('val', data.isdelete);
                            // 角色列表初始化
                            $("#roleListEditDiv").html("");
                            $.get(basePath + "rest/role/getAllRoleByUser", function (roleList) {
                                $.each(roleList, function (index, role) {
                                    $("#roleListEditDiv").append("<div class='ritem'><input type='checkbox' name='roleidlist' value='" + role.id + "'/><span>" + role.name + "</span></div>");
                                });
                                var roleIdList = data.roleidlist;
                                if (roleIdList.length > 0) {
                                    $.each(roleIdList, function (index, roleId) {
                                        $("#roleListEditDiv :checkbox[value='" + roleId + "']").prop("checked", true);
                                    });
                                }
                            });
                            // 树初始化 树初始化过程中对坐席表也进行了初始化 所以不需要单独初始化
                            userEditFun.editTreeInit();
                        }
                    }
                });
            });
            // 工号输入框失去焦点后 触发的事件
            $("#editUserModal input[name='account']").off("keyup").on("keyup", function () {
                var provinceCode = $("#editUserForm input[name='provinceCode']").val();
                var account = $(this).val();
                if (account != '') {
                    $("#editUserForm input[name='username']").val(provinceCode + account);
                    $("#usernameEditSpan").text(provinceCode + account);
                }
            });
        },
        editTreeInit: function () {
            // 判断用户是不是质检或者坐席
            var isQcOrSeat = baseFun.userTypeCheck();
            if (isQcOrSeat == "yes") {
                $("#editUserModal input[name='groupname']").attr("disabled", "disabled");
                return false;
            }
            // 树初始化
            $('#editTree').jstree("destroy");
            $('#editTree').data('jstree', false).empty();
            $("#editTree").jstree({
                "core": {
                    "animation": false,
                    "multiple": false,
                    "check_callback": true,
                    'data': function (obj, callback) {
                        $.ajax({
                            type: "GET",
                            url: basePath + 'rest/group/showGroupTree',
                            dataType: "json",
                            async: false,
                            success: function (result) {
                                if (result != null) {
//                                    var arr = [];
//                                    arr.push(result);
                                    callback.call(this, orgTree.loopMenu(result, true));
                                }
                            }
                        });
                    }
                },
                "types": {
                    "default": {
                        "icon": "jstree-folder"
                    },
                    "html": {
                        "icon": "jstree-file"
                    }
                },
                "plugins": ["types", "search", "unique"]
            }).on("loaded.jstree", function (e, data) {
                // 初始化选择项
                var instance = data.instance;
                // 获取已选中的菜单项
                var groupId = $("#editUserForm input[name='groupid']").val();
                instance.select_node(groupId);
            });
            // 隐藏树
            $('#editTree').on("changed.jstree", function (e, data) {
                if (data.selected > 0) {
                    var groupId = parseInt(data.selected);
                    $("#editUserForm input[name='groupid']").val(groupId);
                    $("#editUserForm input[name='groupname']").val(data.instance.get_selected(true)[0].text);
                    $("#editTree").css("display", "none");
                    // 获取机构id对应的省份编码 用来给用户名赋值
                    $.get(basePath + "rest/group/selectProvinceCodeByGroupId?groupId=" + groupId, function (data) {
                        $("#editUserForm input[name='provinceCode']").val(data);
                        // 读取判断工号是否输入了值
                        var account = $("#editUserForm input[name='account']").val();
                        if (account != '') {
                            $("#editUserForm input[name='username']").val(data + account);
                            $("#usernameEditSpan").text(data + account);
                        }
                    });
                }
            });
        },
        showEditTree: function () {
            $("#editUserForm input[name='groupname']").off("click").on("click", function () {
                // 显示树 需要做成自动显示和隐藏
                $("#editTree").css("display", "block");
            });
        },
        save: function () {
            $("#editSaveBtn").off("click").on("click", function () {
                var bv = $('#editUserForm').data('bootstrapValidator');
                bv.validate();
                if (bv.isValid()) {
                    $.ajax({
                        type: "post",
                        url: basePath + "rest/users/userUpdate",
                        data: $("#editUserModal form").serialize(),
                        success: function (data) {
                            if (data.type == "success") {
                                $("#editUserModal").modal("hide");
                                $("#userTable").bootstrapTable("refresh");
                                toastr.success("用户修改成功");
                            } else {
                                toastr.error("用户修改失败");
                            }
                        }
                    });
                }
            });
        }
    };

    // 状态修改
    var statusChangeFun = {
        init: function () {
            statusChangeFun.batchOn();
            statusChangeFun.batchOff();
            statusChangeFun.modalInit();
        },
        batchOn: function () {
            // 批量启用按钮事件绑定
            $("#batchOnBtn").off("click").on("click", function () {
                //先判断选中的用户状态
                var rows = $("#userTable").bootstrapTable("getSelections");
                if (rows.length == 0) {
                    toastr.error('请至少选择一条用户信息');
                } else {
                    var idList = [];
                    // 标记选中的用户里面是否有启用状态的用户
                    var hasNormal = false;
                    // 标记选中的用户里面是否有冻结状态的用户
                    var hasFreeze = false;
                    // 标记选中的用户里面是否有过期状态的用户
                    var hasExpire = false;
                    // 标记选中的用户里面是否有停用/注销状态的用户
                    var hasLogout = false;
                    $.each(rows, function (index, row) {
                        if (row.isdelete == '0') hasNormal = true;
                        if (row.isdelete == '1') hasFreeze = true;
                        if (row.isdelete == '2') hasExpire = true;
                        if (row.isdelete == '3') hasLogout = true;
                        idList.push(row.id);
                    });
                    if (hasNormal) {
                        toastr.error('所选的用户中包含已启用的用户');
                        return;
                    }
                    // 操作状态与用户id
                    $("#firstModal #status").val("0");
                    $("#firstModal #ids").val(idList.join(","));
                    // 先拼接好操作成功后的提示信息
                    var message = [];
                    if (hasFreeze) message.push("被冻结的账号已恢复正常");
                    if (hasExpire) message.push("过期的账号已恢复正常，且登录密码已重置成初始密码");
                    if (hasLogout) message.push("被停用的账号已恢复正常");
                    $("#firstModal #successTips").val(message.join(";"));
                    // 确认模态框提示内容
                    $("#firstModal #firstModalLabel").text("用户启用");
                    $("#firstModal #firstTips").text("您确定将账号恢复正常吗？");
                    $("#secondModal #secondModalLabel").text("用户启用");
                    $("#secondModal #secondTips").text("确定要继续操作吗？");
                    if (hasExpire) {
                        $("#firstModal #firstTips").append("过期的账号会重置成初始密码");
                    }
                    $("#firstModal").modal("show");
                }
            });
        },
        batchOff: function () {
            // 批量停用按钮事件绑定
            $("#batchOffBtn").off("click").on("click", function () {
                //先判断选中的用户状态
                var rows = $("#userTable").bootstrapTable("getSelections");
                if (rows.length == 0) {
                    toastr.error('请至少选择一条用户信息');
                } else {
                    var idList = [];
                    var flag = true;
                    $.each(rows, function (index, row) {
                        // 判断要操作的用户的状态 与要修改的用户状态是否相同
                        if (row.isdelete != '0') {
                            flag = false;
                        }
                        idList.push(row.id);
                    });
                    if (!flag) {
                        toastr.error('仅能对正常状态的用户进行停用，所选的用户中包含非正常状态的用户');
                        return;
                    }
                    // 操作状态与用户id
                    $("#firstModal #status").val("3");
                    $("#firstModal #ids").val(idList.join(","));
                    // 先拼接好操作成功后的提示信息
                    $("#firstModal #successTips").val("用户停用操作成功");
                    // 确认模态框提示内容
                    $("#firstModal #firstModalLabel").text("用户停用");
                    $("#firstModal #firstTips").text("停用后原密码将改为初始密码，是否确定？");
                    $("#secondModal #secondModalLabel").text("用户停用");
                    $("#secondModal #secondTips").text("确定要继续操作吗？");
                    $("#firstModal").modal("show");
                }
            });
        },
        // 两次弹窗初始化
        modalInit: function () {
            // 第一次确认弹窗
            $("#firstModal .csavebtn").off("click").on("click", function () {
                $("#firstModal").modal("hide");
                $("#secondModal").modal("show");
            });
            // 第二次确认弹窗
            $("#secondModal .csavebtn").off("click").on("click", function () {
                var idList = $("#firstModal #ids").val().split(',');
                var status = $("#firstModal #status").val();
                // 批量操作
                $.ajax({
                    type: "post",
                    url: basePath + "rest/users/userStatusBatch",
                    data: {idList: idList, isdelete: status},
                    traditional: true,
                    success: function (data) {
                        $("#secondModal").modal("hide");
                        if (data.type == "success") {
                            toastr.success($("#firstModal #successTips").val());
                        } else {
                            toastr.error(data.message);
                        }
                        $("#userTable").bootstrapTable("refresh");
                    }
                });
            });
        }
    };

    // 用户删除
    var userDeleteFun = {
        init: function () {
            userDeleteFun.batch();
            userDeleteFun.confimDelete();
        },
        batch: function () {
            // 批量删除按钮事件绑定
            $("#batchDeleteBtn").off("click").on("click", function () {
                // 初始化要删除的id值
                $("#deleteId").val("");
                // 先获取选中的行
                var rows = $("#userTable").bootstrapTable("getSelections");
                if (rows.length == 0) {
                    toastr.error('请选择行');
                } else {
                    var ids = [];
                    var isCanDelete = true;
                    $.each(rows, function (index, row) {
                        if (row.isdelete == 0) {
                            isCanDelete = false;
                        }
                        ids.push(row.id);
                    });
                    if (!isCanDelete) {
                        toastr.error('要删除的用户已启用，不可以删除');
                        return false;
                    }
                    $("#deleteId").val(ids.join(","));
                    // 弹出删除确认模态框
                    $("#deleteModal").modal("show");
                }
            });
        },
        confimDelete: function () {
            // 在删除模态框中点击确定时触发的删除事件绑定
            $("#deleteModal .csavebtn").off("click").on("click", function () {
                $("#deleteModal").modal("hide");
                $("#delete2Modal").modal("show");
            });
            $("#delete2Modal .csavebtn").off("click").on("click", function () {
                var idList = $("#deleteId").val().split(",");
                $.ajax({
                    type: "post",
                    url: basePath + "rest/users/usersDeleteBatch",
                    data: {idList: idList},
                    traditional: true,
                    success: function (data) {
                        // 相应后关闭model框
                        $("#delete2Modal").modal("hide");
                        if (data.type == "success") {
                            toastr.success('删除成功');
                        } else {
                            toastr.error(data.message);
                        }
                        // 刷新表格
                        $("#userTable").bootstrapTable("refresh");
                    }
                });
            });
        },
    };

    // 批量导入
    var importfile = {
        init: function () {
            importfile.importModalInit();
            importfile.ifile();
            importfile.confimImport();
        },
        importModalInit: function () {
            $("#importModal").on("show.bs.modal", function () {
                // 初始化省份信息
                $.get(basePath + "rest/area/showAllAreas", function (areaList) {
                    if (areaList != null) {
                        // 判断用户是不是集团人员
                        $.get(basePath + "rest/area/getAreaInfo", function (areaInfo) {
                            if (areaInfo == null || areaInfo == "") {
                                // 说明为超管或者集团人员 页面上要多一个请选择选项
                                $("#importForm :input[name='areaid']").html("").append("<option value='' selected>请选择</option>").append("<option value='9999'>集团</option>");
                            }
                            $.each(areaList, function (index, area) {
                                $("#importForm :input[name='areaid']").append("<option value='" + area.id + "'>" + area.area + "</option>");
                            })
                            $("#importForm :input[name='areaid']").selectpicker('refresh');
                        });
                    }
                });
                // 初始化文件上传控件
                $("#uploadDiv").html("").append("<div class='file-loading'><input id='uploadFile' name='uploadFile' type='file' /></div><div id='errorBlock' class='help-block'></div>");
                $("#uploadFile").fileinput({
                    language: 'zh',
                    uploadUrl: basePath + "rest/users/batchImportUser2",
                    allowedFileExtensions: ['xls', 'xlsx'],
                    elErrorContainer: '#errorBlock',
                    showPreview: false,
                    showUpload: false,
                    maxFileCount: 1,
                    enctype: 'multipart/form-data',
                    uploadExtraData: function (previewId, index) {
                        var data = {
                            areaid: $("#importForm :input[name='areaid']").val()
                        };
                        return data;
                    }
                }).on("fileuploaded", function (event, data, previewId, index) {
                    var response = data.response;
                    if (response.type == "success") {
                        $("#importModal").modal("hide");
                        // 弹出确认提示模态框
                        $("#enshureModal").modal("show");
                        $("#enshureModal-text").text(response.message);
                       // toastr.success(response.message);
                        //刷新用户列表
                        $("#userTable").bootstrapTable("refresh");
                    } else {
                        $("#importModal").modal("hide");
                        $("#enshureModal").modal("show");
                        $("#enshureModal-text").text(response.message);
                        //toastr.error(response.message);
                    }
                });
            });
        },
        confimImport: function () {
            // 在导入确定模态框中点击确定时触发的事件绑定
            $("#enshureModal .csavebtn").off("click").on("click", function () {
                        $("#enshureModal").modal("hide");
            });
        },
        ifile: function () {
            $("#importConfirmBtn").off("click").on("click", function () {
                var areaid = $('#importForm :input[name="areaid"] option:selected').val();
                if (areaid == "") {
                    toastr.error("请选择省份");
                    return false;
                }
                var file = $("#uploadFile").val();
                if (file == "") {
                    toastr.error("请选择要上传的文件");
                    return false;
                }
                // else if(file.substring(file.lastIndexOf(".")) != ".xls"){
                //     toastr.error("上传文件格式错误，请使用低版本excel文件");
                //     return false;
                // }
                // 校验通过上传
                $("#uploadFile").fileinput("upload");
            });
        }
    }

    // 密码初始化
    var passwordInitFun = {
        init: function () {
            passwordInitFun.modalInit();
            passwordInitFun.passReset();
        },
        passReset: function () {
            $("#passwordInitBtn").off("click").on("click", function () {
                // 先获取选中的行
                var rows = $("#userTable").bootstrapTable("getSelections");
                if (rows.length == 0) {
                    toastr.error('请选择行');
                } else if (rows.length > 1) {
                    toastr.error('只能对单个用户的密码进行初始化');
                } else {
                    var id = rows[0].id;
                    $("#passResetModal #resetId").val(id);
                    $("#passResetModal").modal("show");
                }
            });
        },
        // 两次弹窗初始化
        modalInit: function () {
            // 第一次确认弹窗
            $("#passResetModal .csavebtn").off("click").on("click", function () {
                $("#passResetModal").modal("hide");
                $("#passReset2Modal").modal("show");
            });
            // 第二次确认弹窗
            $("#passReset2Modal .csavebtn").off("click").on("click", function () {
                var id = $("#passResetModal #resetId").val();
                // 批量操作
                $.ajax({
                    type: "post",
                    url: basePath + "rest/users/passwordInit",
                    data: {id: id},
                    success: function (data) {
                        $("#passReset2Modal").modal("hide");
                        if (data.type == "success") {
                            toastr.success('密码初始化成功');
                        } else {
                            toastr.error('密码初始化失败');
                        }
                    }
                });
            });
        }
    };

    //    授权 因为组对组的设定优于人对组 此处授权时 已确定用户所在组 所以直接使用组对组设置
    var power = {
        jstreeRData: [],
        init: function () {
            $("#powerBtn").on("click", function () {
                var rows = $("#userTable").bootstrapTable("getSelections");
                if (rows.length == 0 || rows.length > 1 || (rows.length == 1 && rows[0].group.type != 1)) {
                    toastr.error('请选择一条所属机构为质检的用户信息');
                } else {
                    // 所选用户id
                    var userId = rows[0].id;
                    // 所选质检组id
                    var groupId = rows[0].group.id;
                    // 取出该用户设置的坐席组信息（包括：1.所在组设置的坐席组信息；2.个人设置的坐席组信息）
                    $("#powerModal").modal("show").attr({"data-user-id": userId, "data-group-id": groupId});

                    power.jstreeRData = [];
                    power.initTree($("#jstreeL"), basePath + "rest/group/receiveUnAuthSeatGroup");
                    power.initTree($("#jstreeR"), basePath + "rest/group/receiveAuthSeatGroup");
                    power.search($("#jstreeL"));
                    power.search($("#jstreeR"));
                }
            });
            power.unAuthon();
        },
        initTree: function (elem, url) {
            var rows = $("#userTable").bootstrapTable("getSelections");
            var areaname = rows[0].group.areaname;
            // 树初始化
            elem.jstree("destroy");
            elem.data('jstree', false).empty();
            elem.jstree({
                "core": {
                    "animation": false,
                    "multiple": true,
                    "check_callback": true,
                    'data': function (obj, callback) {
                        $.ajax({
                            type: "GET",
                            url: url,
                            dataType: "json",
                            data: {
                                userId: $("#powerModal").attr("data-user-id"),
                                groupId: $("#powerModal").attr("data-group-id")
                            },
                            success: function (result) {
                                if (result != null && result.length > 0) {
                                    if (elem.attr("id") == "jstreeR") {
                                        power.jstreeRData = [];
                                    }
                                    var arr = [];
                                    if (areaname == null) {
                                        areaname = "集团";
                                    }
                                    reformResult = [{
                                        "areaId": -1,
                                        "area": areaname,
                                        "allGroupList": result
                                    }];

                                    for (var i = 0; i < reformResult.length; i++) {
                                        var obj = {};
                                        obj.id = reformResult[i].areaId;
                                        obj.text = reformResult[i].area;
                                        obj.flag = 0;//标识能不能传参到后台；0：不能，1：能
                                        obj.children = [];
                                        var allGroupList = reformResult[i].allGroupList;
                                        for (var j = 0; j < allGroupList.length; j++) {
                                            var obj1 = {};
                                            obj1.id = allGroupList[j].parentId;
                                            obj1.text = allGroupList[j].parentName;
                                            obj1.flag = 0;//标识能不能传参到后台
                                            obj1.children = [];
                                            var groupList = allGroupList[j].seatGroupList;
                                            if (groupList.length > 0) {
                                                for (var k = 0; k < groupList.length; k++) {
                                                    var obj2 = {};
                                                    obj2.id = groupList[k].id;
                                                    if (elem.attr("id") == "jstreeR") {
                                                        power.jstreeRData.push(obj2.id);
                                                    }
                                                    obj2.text = groupList[k].name;
                                                    obj2.flag = 1;
                                                    obj2.children = [];
                                                    if (obj1.id == null) {
                                                        obj.children.push(obj2);
                                                    } else {
                                                        obj1.children.push(obj2);
                                                    }
                                                }
                                            }
                                            if (obj.id == null) {
                                                arr.push(obj1);
                                            } else {
                                                if (obj1.id == null) {
                                                    continue;
                                                } else {
                                                    obj.children.push(obj1);
                                                }
                                            }
                                        }
                                        if (obj.id != null) {
                                            arr.push(obj)
                                        }
                                    }
                                }
                                callback.call(this, orgTree.loopMenu(arr));
                            }
                        });
                    }
                },
                "types": {
                    "default": {
                        "icon": "jstree-folder"
                    },
                    "html": {
                        "icon": "jstree-file"
                    }
                },
                "plugins": ["types", "search", "unique", "checkbox"],
                "checkbox": {
                    "keep_selected_style": false
                }
            }).on("loaded.jstree", function (e, data) {
                if (elem.attr("id") == "jstreeR") {
                    // 获取需要禁用菜单项
                    $.ajax({
                        type: "GET",
                        url: basePath + "rest/group/selectAuthSeatGroup",
                        dataType: "json",
                        data: {
                            groupId: $("#powerModal").attr("data-group-id")
                        },
                        success: function (result) {
                            if (result != null && result.length > 0) {
                                var nodeIds = [-1];
                                for (var i = 0; i < result.length; i++) {
                                    if (result[i].parentId != null) {
                                        nodeIds.push(result[i].parentId)
                                    }

                                    var groupList = result[i].seatGroupList;
                                    if (groupList.length > 0) {
                                        for (var j = 0; j < groupList.length; j++) {
                                            nodeIds.push(groupList[j].id);
                                        }
                                    }
                                }

                                // 初始化选择项
                                var instance = data.instance;
                                // 禁用菜单项
                                instance.disable_node(nodeIds);

                                // 去除power.jstreeRData中组组授权的组织机构id，防止人组授权时多授权
                                var index;
                                for (var i = 0; i < nodeIds.length; i++) {
                                    index = power.jstreeRData.indexOf(parseInt(nodeIds[i]));
                                    if (index > -1) {
                                        power.jstreeRData.splice(index, 1);
                                    }
                                }
                            }
                        }
                    });
                }
            });
        },
        search: function (elem) {
            var btn = elem.prev().find(".fa_btn");
            var input = elem.prev().find("input");
            btn.on("click", function () {
                elem.jstree(true).search(input.val());
                power.scrollSearch(elem);
            });
            input.on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    elem.jstree(true).search(input.val());
                    power.scrollSearch(elem);
                }
            })
        },
        scrollSearch: function (elem) {
            if (elem.find(".jstree-search").length > 0) {
                var odiv = elem.find(".jstree-search").eq(0)[0];
                var top = odiv.offsetTop;
                var height = odiv.offsetHeight;
                var elemTop = elem[0].scrollTop;
                //获取当前屏幕大小
                var size = elem.height();
                //加上元素本身的高度，是元素全部出现事件
                if ((top + height) < (elemTop + size) && (top + height) > elemTop) {

                } else {
                    elem.animate({scrollTop: top - 70}, "slow");
                }
            }
        },
        unAuthon: function () {
            $("#authon").on("click", function () {//授权操作
                power.authonMethods("authon", $("#jstreeL"));
            });
            $("#unAuthon").on("click", function () {//撤销授权操作
                power.authonMethods("unAuthon", $("#jstreeR"));
            });
        },
        authonMethods: function (type, elem) {
            var nodeIds = power.getSelectNodeId(type, elem);
            if ($("#powerModal").attr("data-check") == "false") {
                toastr.error("请选择需要授权的数据", 2000)
                return
            }
            $.ajax({
                type: "GET",
                url: basePath + "rest/users/qcRelationSave",
                dataType: "json",
                traditional: true,
                data: {
                    userId: $("#powerModal").attr("data-user-id"),
                    seatGroupIdList: nodeIds
                },
                success: function (result) {
                    if (result && result.type == "success") {
                        toastr.success("授权成功", 1000);
                        power.initTree($("#jstreeL"), basePath + "rest/group/receiveUnAuthSeatGroup");
                        power.initTree($("#jstreeR"), basePath + "rest/group/receiveAuthSeatGroup");
                    } else {
                        toastr.error("授权失败")
                    }
                }
            });
        },
        getSelectNodeId: function (type, elem) {
            var treeNode = elem.jstree(true); //获取所有选中的节点对象
            treeNode.get_all_checked = function () { //返回所有选中的节点id
                var tmp = new Array;
                for (var i in this._model.data) {
                    if (this.is_undetermined(i) || this.is_checked(i)) {
                        if (this._model.data[i].id != "#") {
                            var node = this._model.data[i];
                            if (node.original.flag == 1) {
                                tmp.push(node.id);
                            }
                        }
                    }
                }
                return tmp;
            };
            var nodeIds = treeNode.get_all_checked();//获取所有选中的节点id
            if (nodeIds.length > 0) {//用来判断有没有选中的节点
                $("#powerModal").attr("data-check", "true")
            } else {
                $("#powerModal").attr("data-check", "false")
            }
            var authonAllNode = power.jstreeRData;//获取所有已授权id
            if (type == "authon") {//授权操作
                nodeIds = nodeIds.concat(authonAllNode);
            } else {//撤销授权操作
                var index;
                for (var j = 0; j < nodeIds.length; j++) {
                    index = authonAllNode.indexOf(parseInt(nodeIds[j]));
                    if (index > -1) {
                        authonAllNode.splice(index, 1);
                    }
                }
                nodeIds = authonAllNode;
            }
            return nodeIds;
        }
    };

    // 基础功能
    var baseFun = {
        init: function () {
            baseFun.search();
            // 用户状态设置
            baseFun.userStatus();
            baseFun.reset();
        },
        // 点击搜索时表格重新加载
        search: function () {
            // 组织机构选择modal弹出时 初始化树
            $("#orgModal").on("show.bs.modal", function () {
                // 判断省份id
                var areaId = $("#areaIdSearch").selectpicker('val');
                var areaName = $("#areaIdSearch").find("option:selected").text();
                // 树初始化
                $('#groupChooseTree').jstree("destroy");
                $('#groupChooseTree').data('jstree', false).empty();
                $("#groupChooseTree").jstree({
                    "core": {
                        "animation": false,
                        "multiple": false,
                        "check_callback": true,
                        'data': function (obj, callback) {
                            $.ajax({
                                type: "GET",
                                url: basePath + 'rest/group/showGroupTree?areaId=' + areaId,
                                dataType: "json",
                                async: false,
                                success: function (result) {
                                    if (result != null) {
                                        if (result.constructor === Array) {
                                            callback.call(this, orgTree.loopMenu(result, true));
                                        } else {
                                            var arr = [];
                                            arr.push(result);
                                            callback.call(this, orgTree.loopMenu(arr, true));
                                        }
                                    }
                                }
                            });
                        }
                    },
                    "types": {
                        "default": {
                            "icon": "jstree-folder"
                        },
                        "html": {
                            "icon": "jstree-file"
                        }
                    },
                    "plugins": ["types", "search", "unique"]
                }).on("loaded.jstree", function (e, data) {
                    // 初始化选择项
                    var instance = data.instance;
                    // 获取已选中的菜单项
                    var groupId = $("#chooseId").val();
                    instance.select_node(groupId);
                });
                // 获取选中的树的节点信息
                $('#groupChooseTree').on("changed.jstree", function (e, data) {
                    if (data.selected > 0) {
                        $("#chooseId").val(data.selected);
                        $("#chooseName").val(data.instance.get_selected(true)[0].text);
                    } else {
                        $("#groupChooseTree").jstree("deselect_all", true);
                        $("#chooseId").val("");
                        $("#chooseName").val("");
                    }
                });
            });
            // 当点击modal的确认按钮时 将节点信息放到搜索框内
            $("#orgModal .csavebtn").off("click").on("click", function () {
                $("#groupIdSearch").val($("#chooseId").val());
                $("#groupNameSearch").val($("#chooseName").val());
                $("#orgModal").modal("hide");
            });
            // 点击取消按钮 清空搜索框内容
            $("#orgModal .cancelbtn").off("click").on("click", function () {
                $("#chooseId").val("");
                $("#chooseName").val("");
                $("#groupIdSearch").val("");
                $("#groupNameSearch").val("");
                $("#orgModal").modal("hide");
            });
            // 搜索
            $("#searchBtn").off("click").on("click", function () {
                $("#userTable").bootstrapTable('refreshOptions', {pageNumber: 1});
                $("#userTable").bootstrapTable('refresh');
            });
            $("body").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    //此处编写用户敲回车后的代码
                    $("#userTable").bootstrapTable('refreshOptions', {pageNumber: 1});
                    $("#userTable").bootstrapTable('refresh');
                }
            })

        },
        //重置
        reset: function () {
            $("#reset").on("click", function () {
                bs.resetSearch($(".cquery"));
                $("#areaIdSearch").selectpicker("val", "");
                $("#areaIdSearch").selectpicker("refresh");
                $("#isDeleteSearch").selectpicker("val", "");
                $("#isDeleteSearch").selectpicker("refresh");
                $("#userTable").bootstrapTable('refreshOptions', {pageNumber: 1});
                $("#userTable").bootstrapTable('refresh');
            })
        },
        userTypeCheck: function () {
            // 是否为坐席或者质检
            var isQcOrSeat;
            $.ajax({
                type: "post",
                url: basePath + "rest/users/userTypeCheck",
                async: false,
                success: function (data) {
                    isQcOrSeat = data;
                }
            });
            return isQcOrSeat;
        },
        // 查询用户状态
        userStatus: function () {
            // 获取所有用户状态 并拼接option
            $.get(basePath + "rest/statusAtt/statusAttsGetByType?type=sys_user_status", function (data) {
                var str = "";
                $.each(data, function (i, e) {
                    str += "<option value=\"" + e.value + "\">" + e.name + "</option>";
                });
                // 给每个下拉框进行初始化
                $("#isDeleteSearch").html(str).selectpicker('refresh');
                $("#isDeleteAdd").html(str).selectpicker('refresh');
            });
        }
    };

    //校验
    var validateFun = {
        init: function () {
            validateFun.initKeyValidator();
            validateFun.initOpen();
        },
        initKeyValidator: function () {
            var option = {
                live: "enabled",
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    groupname: {
                        validators: {
                            notEmpty: {
                                message: '所属组织机构不能为空'
                            }
                        }
                    },
                    realname: {
                        validators: {
                            notEmpty: {
                                message: '真实姓名不能为空'
                            }
                        }
                    },
                    account: {
                        validators: {
                            notEmpty: {
                                message: '工号不能为空'
                            },
                            callback: {
                                message: '该工号已存在',
                                callback: function (value, validator, $field) {
                                    if (value == $field.attr("oldvalue")) {
                                        return true;
                                    }
                                    var isExist = false;
                                    $.ajax({
                                        type: "get",
                                        async: false,
                                        url: basePath + "rest/users/userNameUniqueness?username=" + $field.parent().parent().find("input[name='provinceCode']").val() + value,
                                        success: function (data) {
                                            if (data.type == "success") {
                                                isExist = true;
                                            }
                                        }
                                    });
                                    return isExist;
                                }
                            }
                        }
                    },
                    mobileno: {
                        validators: {
                            notEmpty: {
                                message: '手机号码不能为空'
                            },
                            regexp: {
                                regexp: /^1\d{10}$/,
                                message: '请输入有效的11位手机号码'
                            }
                        }
                    },
                    email: {
                        validators: {
                            notEmpty: {
                                message: '邮箱不能为空'
                            },
                            regexp: {
                                regexp: /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/,
                                message: '请输入有效的邮箱地址'
                            }
                        }
                    },
                    idcard: {
                        validators: {
                            notEmpty: {
                                message: '身份证号不能为空'
                            },
                            regexp: {
                                regexp: /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,
                                message: '请输入有效的身份证号'
                            }
                        }
                    }
                }
            };
            $('#userManageForm').bootstrapValidator(option);
            $('#editUserForm').bootstrapValidator(option);
        },
        initOpen: function () {
            $("#userModal").on("hide.bs.modal", function () {
                $('#userManageForm').data('bootstrapValidator').resetForm(true);
            });
            $("#editUserModal").on("hide.bs.modal", function () {
                $('#editUserForm').data('bootstrapValidator').resetForm(true);
            });
        }
    };

    //所属组织结构
    var orgTree = {
        loopMenu: function (array, isModel) {
            if (array && array.length > 0) {
                for (var i = 0; i < array.length; i++) {
                    var children = array[i]["children"];
                    if (children.length <= 0) {
                        array[i].type = "html"
                    } else {
//                        array[i].state = {"opened": false}
                    }
                    if (isModel) {
                        array[i].state = {"opened": false}
                    } else {
                        array[i].state = {"opened": true}
                    }
                    if (children) {
                        orgTree.loopMenu(children, isModel);
                    }
                }
                return array;
            } else {
                return [];
            }
        }
    };

    var resize = {
        init: function () {
            resize.me();
            $(window).resize(function () {
                resize.me();
            })
        },
        me: function () {
            var winW = $(window).width();
            var winH = $(window).height();
            $(".ibox").width(winW - 20);
            $(".ibox").height(winH - 20);
            bs.autoTableHeight($('#userTable'),winH -$(".cquery").height()-22-$(".obtns").height())
        }
    };

    // 初始化省份选择下拉框
    var areaSelectFun = {
        init: function () {
            $.get(basePath + "rest/area/showAllAreas", function (areaList) {
                if (areaList != null) {
                    // 判断用户是不是集团人员
                    $.get(basePath + "rest/area/getAreaInfo", function (areaInfo) {
                        if (areaInfo == null || areaInfo == "") {
                            // 说明为超管或者集团人员 页面上要多一个请选择选项 和 集团选项（注意：集团的值必须与后台Constants.GROUP_AREAID设置的值一致）
                            $("#areaIdSearch").html("").append("<option value='' selected>请选择</option>").append("<option value='9999'>集团</option>");
                        }
                        $.each(areaList, function (index, area) {
                            $("#areaIdSearch").append("<option value='" + area.id + "' data-code='" + area.code + "'>" + area.area + "</option>");
                        })
                        $("#areaIdSearch").selectpicker('refresh');
                    });
                }
            });

            // 当省份变更时 清空右侧机构信息
            $("#areaIdSearch").on("change", function (data) {
                $("#groupIdSearch").val("");
                $("#groupNameSearch").val("");
            });
        }
    };

    $(function () {
        // 初始化省份信息
        areaSelectFun.init();
        // 表格初始化
        var oTable = new TableInit();
        oTable.Init();
        baseFun.init();
        statusChangeFun.init();
        userDeleteFun.init();
        userAddFun.init();
        userEditFun.init();
        passwordInitFun.init();
        validateFun.init();
        importfile.init();
        resize.init();
        power.init();
        // 导出功能实现
        $(".tableColums li").on("click", function () {
            var allNum = $(".tableColums li").length;
            if ($(this).hasClass("on")) {
                $(this).removeClass("on").find("span").remove();
            } else {
                $(this).addClass("on").append('<span class="fa fa-check-square-o"></span>');
            }
            if ($(".tableColums li.on").length < allNum) {
                $(".exportAll").removeClass("on").find("span").remove();
            } else {
                $(".exportAll").addClass("on").append('<span class="fa fa-check-square-o"></span>');
            }
        });
        $(".exportAll").on("click", function () {
            if ($(this).hasClass("on")) {
                $(this).removeClass("on").find("span").remove();
                $(".tableColums li").removeClass("on").find("span").remove();
            } else {
                $(".tableColums li").addClass("on").append('<span class="fa fa-check-square-o"></span>');
                $(this).addClass("on").append('<span class="fa fa-check-square-o"></span>');
            }
        });
        $(".exportSaveBtn").on("click", function () {
            var arrCode = [];
            var arrName = [];
            $(".tableColums li.on").each(function () {
                arrCode.push($(this).attr("data-code"));
                arrName.push($(this).text());
            });
            var code = arrCode.join(",");
            var name = arrName.join(",");
            var rows = $("#userTable").bootstrapTable("getSelections");
            var userIdList = [];
            $.each(rows, function (i, row) {
                userIdList.push(row.id);
            });
            var isDelete = $("#isDeleteSearch").val() != null ? $("#isDeleteSearch").val().join(",") : "";
            if (code.indexOf("mobileno") == -1 && code.indexOf("idcard") == -1) {
                $("#exportForm input[name='code']").val("exportExcelBtn1");
                $("#exportForm input[name='areaId']").val($("#areaIdSearch").selectpicker("val"));
                $("#exportForm input[name='groupId']").val($("#groupIdSearch").val());
                $("#exportForm input[name='seatGroup']").val($("#groupNameSearch").val());
                $("#exportForm input[name='userName']").val($.trim($("#userNameSearch").val()));
                $("#exportForm input[name='realName']").val($.trim($("#realNameSearch").val()));
                $("#exportForm input[name='account']").val($.trim($("#accountSearch").val()));
                $("#exportForm input[name='status']").val(isDelete);
                $("#exportForm input[name='fileContent']").val(code);
                $("#exportForm input[name='fileContext']").val(name);
                $("#exportForm input[name='userIdList']").val(userIdList.join(","));
                $("#exportForm").attr("action", basePath + "/rest/approval/add-export-task").submit();
                $("#exportModal").modal("hide");
            } else {
                $.ajax({
                    type: "post",
                    url: basePath + "/rest/approval/add-export-task",
                    dataType: "json",
//                contentType: "application/json",
                    data: {
                        code: "exportExcelBtn1",
                        areaId: $("#areaIdSearch").selectpicker("val"),
                        groupId: $("#groupIdSearch").val(),
                        seatGroup: $("#groupNameSearch").val(),
                        account: $.trim($("#accountSearch").val()),
                        userName: $.trim($("#userNameSearch").val()),
                        realName: $.trim($("#realNameSearch").val()),
                        status: isDelete,
                        fileContent: code,
                        fileContext: name,
                        userIdList: userIdList.join(",")
                    },
                    success: function (data) {

                    },
                    complete: function (data, d) {
                        var data = JSON.parse(data.responseText);
                        if (data.code == -1) {
                            toastrCog.error(data.msg)
                        } else {
                            toastrCog.success(data.msg)
                        }
                        $("#exportModal").modal("hide");
                    }
                })
            }

        });
        $("#exportExcelBtn1").off("click").on("click", function () {
            var data = $("#userTable").bootstrapTable("getData");
            if (data.length == 0) {
                toastrCog.error("没有数据可以导出！")
                return
            }
            $("#exportModal").modal("show");
            $(".tableColums li").addClass("on").append('<span class="fa fa-check-square-o"></span>');
            $(".exportAll").addClass("on").append('<span class="fa fa-check-square-o"></span>');
//            // 获取选中的行
//            var rows = $("#userTable").bootstrapTable("getSelections");
//            var userIdList = [];
//            $.each(rows, function (i, row) {
//                userIdList.push(row.id);
//            });
//            // 获取其他查询参数
//            $("#exportForm input[name='userIdList']").val(userIdList.join(","));
//            $("#exportForm input[name='areaId']").val($("#areaIdSearch").selectpicker("val"));
//            $("#exportForm input[name='groupId']").val($("#groupIdSearch").val());
//            $("#exportForm input[name='userName']").val($.trim($("#userNameSearch").val()));
//            $("#exportForm input[name='realName']").val($.trim($("#realNameSearch").val()));
//            $("#exportForm input[name='account']").val($.trim($("#accountSearch").val()));
//            var isDelete = $("#isDeleteSearch").val() != null ? $("#isDeleteSearch").val().join(",") : "";
//            $("#exportForm input[name='isDelete']").val(isDelete);
//            $("#exportForm").attr("action", basePath + "rest/users/exportBase").submit();
        });
        $("#exportExcelBtn2").off("click").on("click", function () {
            // 获取选中的行
            var rows = $("#userTable").bootstrapTable("getSelections");
            var userIdList = [];
            $.each(rows, function (i, row) {
                userIdList.push(row.id);
            });
            // 获取其他查询参数
            $("#exportForm input[name='userIdList']").val(userIdList.join(","));
            $("#exportForm input[name='areaId']").val($("#areaIdSearch").selectpicker("val"));
            $("#exportForm input[name='groupId']").val($("#groupIdSearch").val());
            $("#exportForm input[name='userName']").val($.trim($("#userNameSearch").val()));
            $("#exportForm input[name='realName']").val($.trim($("#realNameSearch").val()));
            $("#exportForm input[name='account']").val($.trim($("#accountSearch").val()));
            var isDelete = $("#isDeleteSearch").val() != null ? $("#isDeleteSearch").val().join(",") : "";
            $("#exportForm input[name='isDelete']").val(isDelete);
            $("#exportForm").attr("action", basePath + "rest/users/exportDetail").submit();
        });
    });
    //点击空白处
    $(document).click(function (e) {
        var _con = $("input[name='groupname'],.otree");
        if (!_con.is(e.target) && _con.has(e.target).length === 0) {
            $('.otree ').hide();
        }
    });
</script>
</body>

</html>